from random import randint

class Heap:

    def __init__(self):
        self.__data = [];
        self.__len = 0;

    def __down(self,index):
        if self.__len<0 or len(self.__data)<=0\
            or index<0 or index>=self.__len :
            return
        u,i,j  = self.__data[index],index,index<<1
        while j<self.__len :
            if j+1<self.__len and self.__data[j]<self.__data[j+1]:
                j += 1
            if self.__data[j]>self.__data[i] :
                self.__data[i] = self.__data[j]
                i = j
                j = i<<1
            else :
                break
        self.__data[i] = u

    def __up(self,index):
        if index<0 or index >= self.__len :
            return
        u,i,j=self.__data[index],index,index>>1
        while i>0 :
            if self.__data[j]<self.__data[i] :
                self.__data[i] = self.__data[j]
                i = j
                j = i>>1
            else :
                break
        self.__data[i] = u

    def init(self):
        if self.__len<=0 or len(self.__data)<=0 :
            return
        for i in xrange(self.__len/2,-1,-1):
            self.__down(i)

    def add(self,x):
        self.__data.append(x)
        self.__len += 1

    def push(self,x):
        self.__data.append(x)
        self.__len += 1
        self.__up(self.__len-1)

    def pop(self):
        res = self.__data[0]
        self.__data[0] = self.__data.pop()
        self.__len = len(self.__data)
        self.__down(0)
        # self.__len -= 1
        return res


    def out(self):
        print self.__len,':',self.__data

def main():
    n = int(input())
    heap = Heap()
    for i in xrange(n):
        ss = raw_input()
        ss = ss.split(' ')
        s = int(ss[0])
        if s==0 :
            x = int(ss[1])
            heap.push(x)
        elif s==1 :
            print heap.pop()


if __name__=='__main__' :
    main()
